package com.huazi.oss.controller;

import com.huazi.commonutils.CommentResult;
import com.huazi.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author shkstart
 * @create 2021-03-16 14:19
 */
@RestController
@CrossOrigin
@RequestMapping("/eduoss/fileoss")
public class OssController {
    @Autowired
    private OssService ossService;
    //上传头像方法
    @PostMapping
    public CommentResult uploadOssFile(
            //因为文件上传接收的不是字符串，加上这个可以解决 For input String ""
            @RequestBody(required = false)
                    MultipartFile file){
        //方法返回一个头像路径
        System.out.println("进入file");
        String s = ossService.uploadFileAvatar(file);
        return CommentResult.getOK().data("url",s);
    }
}
